<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort()
			+ path + "/";
%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<!DOCTYPE html>
<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<!-- Meta, title, CSS, favicons, etc. -->
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">

<title>随便打TCS系统</title>

<!-- Bootstrap -->
<link href="<%=basePath%>vendors/bootstrap/dist/css/bootstrap.min.css"
	rel="stylesheet">
<!-- Font Awesome -->
<link
	href="//netdna.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css"
	rel="stylesheet">
<!-- NProgress -->
<link href="<%=basePath%>vendors/nprogress/nprogress.css"
	rel="stylesheet">
<!-- iCheck -->
<link href="<%=basePath%>vendors/iCheck/skins/flat/green.css"
	rel="stylesheet">

<!-- bootstrap-progressbar -->
<link
	href="<%=basePath%>vendors/bootstrap-progressbar/css/bootstrap-progressbar-3.3.4.min.css"
	rel="stylesheet">
<!-- JQVMap -->
<link href="<%=basePath%>vendors/jqvmap/dist/jqvmap.min.css"
	rel="stylesheet" />
<!-- bootstrap-daterangepicker -->
<link
	href="<%=basePath%>vendors/bootstrap-daterangepicker/daterangepicker.css"
	rel="stylesheet">

<!-- 富文本  -->
<link href="<%=basePath%>static/css/quill.snow.css" rel="stylesheet">

<!-- Custom Theme Style -->
<link href="<%=basePath%>build/css/custom.min.css" rel="stylesheet">
<script src="<%=basePath%>vendors/kindeditor/kindeditor-all-min.js"></script>
<script src="<%=basePath%>vendors/kindeditor/lang/zh-CN.js"></script>
</head>

<body class="nav-md">
	<div class="container body">
		<div class="main_container">
			<div class="col-md-3 left_col">
				<div class="left_col scroll-view">
					<div class="clearfix"></div>
					<br />
				</div>
			</div>
			<!-- page content -->
			<div class="right_col" role="main">
				<div class="">
					<div class="row">
						<div class="clearfix"></div>
						<div class="col-md-12 col-sm-12 col-xs-12">
							<div class="x_panel">
								<div class="x_content">
									<form name="myForm" class="form-horizontal form-label-left" novalidate 
						                  method= "post" enctype ="multipart/form-data" id="formUpload" > 
						                 <span class="section">企业动态</span>
						                 <div class="form-group" style="display: none">
											<label class="control-label col-md-3 col-sm-3 col-xs-12">主题</label>
											<div class="col-md-6 col-sm-6 col-xs-12">
												<input type="text" class="form-control"
													placeholder="" id="id" value="${id}">
											</div>
										</div>
										<div class="form-group">
											<label class="control-label col-md-3 col-sm-3 col-xs-12">主题</label>
											<div class="col-md-6 col-sm-6 col-xs-12">
												<input type="text" class="form-control"
													placeholder="" id="theme" value="${theme}">
											</div>
										</div>
										<div class="form-group">
											<label class="control-label col-md-3 col-sm-3 col-xs-12">封面标题</label>
											<div class="col-md-6 col-sm-6 col-xs-12">
												<input type="text" class="form-control"
													placeholder="" id="title" value="${title}">
											</div>
										</div>
										<div class="form-group">
											<label class="control-label col-md-3 col-sm-3 col-xs-12">正文标题</label>
											<div class="col-md-6 col-sm-6 col-xs-12">
												<input type="text" class="form-control"
													placeholder="" id="contenttitle"  value="${contenttitle}">
											</div>
										</div>
										<div class="form-group">
											<label class="control-label col-md-3 col-sm-3 col-xs-12">发布者</label>
											<div class="col-md-6 col-sm-6 col-xs-12">
												<input type="text" class="form-control"
													placeholder="" id="username" value="${username}">
											</div>
										</div>
										
										<div class="form-group">
											<label class="control-label col-md-3 col-sm-3 col-xs-12">跳转地址</label>
											<div class="col-md-6 col-sm-6 col-xs-12">
												<input type="text" class="form-control" placeholder=""
												id="url" value="${url}">
											</div>
										</div>
										
										<div class="item form-group" >
											<label class="control-label col-md-3 col-sm-3 col-xs-12"
												for="name">封面图片 <span class="required"></span>
											</label>
											<div class="col-md-6 col-sm-6 col-xs-12">
												<input class="form-control col-md-7 col-xs-12"
													 id="pic" multiple="multiple" name="pic" required="required" type="file"
													placeholder="请先上传图片" form="formUpload">
												<input class="form-control col-md-7 col-xs-12"
												    style="display:none" type="text" value="${pic}">
											</div>
										</div>
										
										<div class="item form-group" >
											<label class="control-label col-md-3 col-sm-3 col-xs-12"
												for="name">内容图片 <span class="required"></span>
											</label>
											<div class="col-md-6 col-sm-6 col-xs-12">
												<input class="form-control col-md-7 col-xs-12"
													 id="contentPic" multiple="multiple" name="contentPic" required="required" type="file"
													placeholder="请先上传图片" form="formUpload">
												<input class="form-control col-md-7 col-xs-12"
												    style="display:none" type="text" value="${contentPic}">
											</div>
										</div>

										<div class="item form-group">
											<label class="control-label col-md-3 col-sm-3 col-xs-12"
												   for="name">内容<span class="required">*</span>
											</label>
											<div class="col-md-6 col-sm-6 col-xs-12">
												<div id="standalone-container">
													<div id="toolbar-container">
												<span class="ql-formats">
												<!-- <select class="ql-font"></select> -->
												<select class="ql-size"></select>
												</span>
														<span class="ql-formats">
												<button class="ql-list" value="ordered"></button>
												</span>
														<span class="ql-formats">
												<select class="ql-align"></select>
												</span>
														<span class="ql-formats">
												<button class="ql-image"></button>
												</span>
													</div>
													<div id="editor-container" style="height:400px">${content}</div>
												</div>
											</div>
										</div>

										<div class="form-group" id="personal" style="display:none">
											<label class="control-label col-md-3 col-sm-3 col-xs-12">接收人</label>
											<div class="col-md-6 col-sm-6 col-xs-12">
												<input type="text" class="form-control" placeholder=""
												id="receiveid" value="${receiveid}">
											</div>
										</div>
										<div class="form-group">
											<div class="col-md-12 col-sm-12 col-xs-12 col-md-offset-3">
												<a type="submit" class="btn btn-primary"
													href="javascript:void(0)"
													onclick="history.back(-1);">返回</a>
												<input id="revise" type="button" class="btn btn-success"
													value="修改">
											</div>
										</div>
									</form>
								</div>
							</div>
						</div>
					</div>
				</div>
			</div>
			<!-- 富文本 -->
			<script src="<%=basePath%>static/js/katex.min.js"></script>
			<script  src="<%=basePath%>static/js/highlight.min.js"></script>
			<script src="<%=basePath%>static/js/quill.js"></script>
			<script src="<%=basePath%>vendors/jquery/dist/jquery.min.js"></script>
			<script>
				var quill = new Quill('#editor-container', {
					modules: {
						formula: true,
						syntax: true,
						toolbar: '#toolbar-container'
					},
					placeholder: '请输入内容',
					theme: 'snow'
				});
			</script>
			<script type="text/javascript">
			$('#revise').click(function () {
				// 上传文件
			    var pic = $("#pic")[0].files[0];
			    var contentPic = $("#contentPic")[0].files[0];
			    var picUrl = "";
			    var contentPicUrl="";
			    
			    if(pic != null || pic != undefined){
			    	var fileName = pic.name.substring(pic.name.lastIndexOf(".")+1).toLowerCase();
					if(fileName !="jpg" && fileName !="jpeg" && fileName !="png"&& fileName !="gif" ){
						alert("只能上传 .jpg .png .jpeg .gif类型的文件");
			            return false;
					}
			    	picUrl = addfile(pic);
			 	}
			    
			    if(contentPic != null || contentPic != undefined){
			    	var fileName = contentPic.name.substring(contentPic.name.lastIndexOf(".")+1).toLowerCase();
					if(fileName !="jpg" && fileName !="jpeg" && fileName !="png"&& fileName !="gif" ){
						alert("只能上传 .jpg .png .jpeg .gif类型的文件");
			            return false;
					}
					contentPicUrl = addfile(contentPic);
			 	}
			    
			     ajaxPost(picUrl,contentPicUrl);
			 });
			
			    function addfile(file) {
					var fm = new FormData();
					fm.append('file', file);
					$.ajax({
						url: "<%=basePath%>layfile/uploadFile1",
						type : 'POST',
						data : fm,
						async : false,
						contentType : false, //禁止设置请求类型
						processData : false, //禁止jquery对DAta数据的处理,默认会处理
						//禁止的原因是,FormData已经帮我们做了处理
						success : function(result) {
							file = result.json;
						}
					});
					return file;
				}
            </script>
             <script type="text/javascript">
				// ajax 对象
				function ajaxObject() {
					var xmlHttp;
					try {
						// Firefox, Opera 8.0+, Safari
						xmlHttp = new XMLHttpRequest();
					} catch (e) {
						// Internet Explorer
						try {
							xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
						} catch (e) {
							try {
								xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
							} catch (e) {
								alert("您的浏览器不支持AJAX！");
								return false;
							}
						}
					}
					return xmlHttp;
				}
			
			
				// ajax post请求：
				function ajaxPost(pic,contentPic) {
					var id = $("#id").val();
					var title = $("#title").val();
					var contenttitle = $("#contenttitle").val();
					var theme = $("#theme").val();
					var username = $("#username").val();
					var url = $("#url").val();
					var content = encodeURIComponent($(".ql-editor").html());//获取富文本内容
					var receiveid = $("#receiveid").val();
					var ajax = ajaxObject();
					ajax.open("post", "updateCompanyNews?url=" + url +
						"&id=" + id +
						"&title=" + title +
						"&contenttitle=" + contenttitle +
						"&username=" + username +
						"&receiveid=" + receiveid +
						"&theme=" + theme +
						"&content=" + content +
						"&contentPic=" + contentPic +
						"&pic=" + pic, true);
					ajax.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
					ajax.onreadystatechange = function() {
						if (ajax.readyState == 4) {
							if (ajax.status == 200) {
								var result = ajax.responseText;
								if (result == "success") {
									//请求成功
									alert("修改成功");
									location.href = "content_qiyedongtai";
								} else {
									//创建失败
									alert(result);
								}
							} else if (ajax.status == 0) {
								//请求失败
								alert("您使用的火狐浏览器不支持本次操作，请更换浏览器重试");
							} else {
								//请求失败
								alert("请求终止，请检查操作或联系客服咨询" + ajax.status);
							}
						} else {
						}
					};
					ajax.send();
			
				}
			</script>
		</div>
	</div>
	<!-- jQuery -->
	<script src="<%=basePath%>vendors/jquery/dist/jquery.min.js"></script>
	<!-- Bootstrap -->
	<script src="<%=basePath%>vendors/bootstrap/dist/js/bootstrap.min.js"></script>
	<!-- FastClick -->
	<script src="<%=basePath%>vendors/fastclick/lib/fastclick.js"></script>
	<!-- NProgress -->
	<script src="<%=basePath%>vendors/nprogress/nprogress.js"></script>
	<!-- bootstrap-daterangepicker -->
	<script src="<%=basePath%>vendors/moment/min/moment.min.js"></script>
	<script
		src="<%=basePath%>vendors/bootstrap-daterangepicker/daterangepicker.js"></script>
	<!-- Chart.js -->
	<script src="<%=basePath%>vendors/Chart.js/dist/Chart.min.js"></script>

	<!-- Custom Theme Scripts -->
	<script src="<%=basePath%>build/js/custom.min.js"></script>
</body>
</html>